package com.codepilot.server.service.impl;

import com.codepilot.server.mapper.FavorMapper;
import com.codepilot.server.model.entity.Favor;
import com.codepilot.server.service.FavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavorServiceImpl implements FavorService {
    @Autowired
    private FavorMapper favorMapper;

    public Favor getFavor(Integer userId, Integer problemUid) {
        return favorMapper.getFavor(userId, problemUid);
    }
    public List<Favor> getFavorList(Integer userId) {
        return favorMapper.getFavorList(userId);
    }
    public Integer createFavor(Favor favor) {
        return favorMapper.insertFavor(favor);
    }
    public Integer updateFavor(Favor favor) {
        return favorMapper.updateFavor(favor);
    }
    public Integer deleteFavor(Integer userId, Integer problemUid) {
        Favor favor = getFavor(userId, problemUid);
        if (favor != null) {
            return favorMapper.deleteFavor(favor.getId());
        } else {
            return 0;
        }
    }
}
